﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace LanusMarket.Models
{
    public class Aviso 
    {   
        [Key]
        public int AvisoID { get; set; }
        
        [Required]
        [Display(Name="Nombre")]
        public string Nombre { get; set; }

        [Required]
        [Display(Name = "Ubicacion")]
        public int UbicacionID { get; set; }

        [Display(Name = "Ubicacion")]
        public virtual Ubicacion Ubicacion { get; set; }

        [Required]
        [Display(Name = "Categoria")]
        public int CategoriaID { get; set; }
                
        [Display(Name = "Categoria")]
        public virtual Categoria Categoria {get; set;}

        [Required]
        [Display(Name = "Keys")]
        public virtual ICollection<SearchKey> SearchKeys { get; set; }
    }

    public class Categoria
    {
        [Key]
        public int CategoriaID { get; set; }

        [Required]
        [Display(Name = "Nombre")]
        public string Nombre { get; set; }

        [Display(Name = "Avisos")]
        public virtual ICollection<Aviso> Avisos {get; set;}

    }

    public class Ubicacion
    {
        [Key]
        public int UbicacionID { get; set; }

        [Required]
        [Display(Name = "Titulo")]
        public string Titulo { get; set; }

        [Display(Name = "Descripcion")]
        public string Descripcion { get; set; }

        [DisplayFormat(ConvertEmptyStringToNull = false)]
        [RegularExpression(@"^(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$", ErrorMessage = "{0} debe tener el siguiente formato mail@dominio.com")]
        [Display(Name = "Email")]
        public string Email { get; set; }

        [DisplayFormat(ConvertEmptyStringToNull = false)] 
        [RegularExpression(@"^\d{4}-\d{4}$", ErrorMessage = "{0} debe tener el siguiente formato ####-####")]
        [Display(Name = "Telefono")]
        public string Telefono { get; set; }

        [Display(Name = "Link")]
        public string Link { get; set; }

        [Required]
        [Display(Name="Latitud")]
        public string Latitud { get; set; }

        [Required]
        [Display(Name = "Longitud")]
        public string Longitud { get; set; }

        [Required]
        [Display(Name = "Calle")]
        public string Calle { get; set; }

        [Required]
        [Display(Name = "Altura")]
        public int Altura { get; set; }
              
        [Display(Name = "Codigo Postal")]
        public int? CodigoPostal { get; set; }
      
        [Required]
        [Display(Name = "Localidad")]
        public int LocalidadID { get; set; }
                
        [Display(Name = "Localidad")]
        public virtual Localidad Localidad { get; set; }

        [Required]
        [Display(Name = "Provincia")]
        public int ProvinciaID { get; set; }
                
        [Display(Name = "Provincia")]
        public string Provincia { get; set; }

        [Required]
        [Display(Name = "Pais")]
        public int PaisID { get; set; }
                
        [Display(Name = "Pais")]
        public string Pais { get; set; }

        [Required]
        [Display(Name = "Keys")]
        public IEnumerable<int> SearchKeysID { get; set; }
                
        [Display(Name = "Keys")]
        public virtual ICollection<SearchKey> SearchKeys {get;set;}
    }
    
    public class Localidad
    {
        [Key]
        public int LocalidadID { get; set; }

        [Required]
        [Display(Name = "Nombre")]
        public string Nombre { get; set; }

        [Required]
        [Display(Name="Provincia")]
        public int ProvinciaID { get; set; }

        [Display(Name = "Provincia")]
        public virtual Provincia Provincia {get;set;}

        [Display(Name = "Ubicaciones")]
        public virtual ICollection<Ubicacion> Ubicaciones { get; set; }
    }

    public class Provincia
    {
        [Key]
        public int ProvinciaID { get; set; }

        [Required]
        [Display(Name = "Nombre")]
        public string Nombre { get; set; }

        [Required]
        [Display(Name="Pais")]
        public int PaisID { get; set; }

        [Display(Name="Pais")]
        public virtual Pais Pais { get; set; }

        [Display(Name = "Localidades")]
        public virtual ICollection<Localidad> Localidades { get; set; }       
    }

    public class Pais
    {
        [Key]
        public int PaisID { get; set; }

        [Required]
        [Display(Name = "Nombre")]
        public string Nombre { get; set; }
                
        [Display(Name = "Provincias")]
        public virtual ICollection<Provincia> Provincias { get; set; }
    }

    public class SearchKey
    {
        [Key]
        public int SearchKeyID { get; set; }

        [Required]
        [Display(Name="Valor")]
        public string Valor { get; set; }

        [Display(Name = "Ubicaciones")]
        public virtual ICollection<Ubicacion> Ubicaciones { get; set; }

        [Display(Name = "Avisos")]
        public virtual ICollection<Aviso> Avisos { get; set; }

        [Display(Name="Key Relacionadas")]
        public virtual ICollection<SearchKey> KeyRelated { get; set; }

        public override string ToString()
        {
            return this.Valor + ";";
        }
    }
}